package com.xiaoyuan.minicore.aop;

import java.lang.reflect.Method;
import java.util.List;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * @Auther: xiaoyuan
 * @Date: 2020/4/29
 * @Description:
 */
public class BaseAspect implements MethodInterceptor {

    private List<Handler> handlers;

    @SuppressWarnings("unchecked")
    public <T> T getProxy(Class<T> cls,List<Handler> handlers) {
        this.handlers = handlers;
        return (T) Enhancer.create(cls, this);
    }

    @Override
    public Object intercept(Object proxy, Method methodTarget, Object[] args, MethodProxy methodProxy) throws Throwable {
        return new Chain(handlers,proxy,methodTarget,args,methodProxy).proceed();
    }

}